package com.jjx.trainingapi.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.jjx.trainingapi.common.RT;
import com.jjx.trainingapi.entity.param.DcUserFriendsParam;
import com.jjx.trainingapi.entity.po.DcUserFriendsComment;
import com.jjx.trainingapi.entity.vo.CommentListVo;
import com.jjx.trainingapi.service.DcUserFriendsCommentService;
import com.jjx.trainingapi.service.DcUserFriendsService;
import com.jjx.trainingapi.util.LoginManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 朋友圈的controller
 *
 * @author LoveHuahua
 * @date 2022年06月03日 23:25
 * @description believe in yourself
 */
@RestController
@RequestMapping("/friends")
@SaCheckLogin
public class FriendsController {

    @Autowired
    DcUserFriendsService friendsService;
    @Autowired
    DcUserFriendsCommentService friendsCommentService;

    /**
     * 获取朋友圈列表
     *
     * @return
     */
    @PostMapping("/getList")
    public RT getList() {
        return RT.ok(friendsService.getList());
    }

    /**
     * 添加分享数量+1
     *
     * @param friends
     * @return
     */
    @PostMapping("/addShard")
    public RT addShard(@RequestBody DcUserFriendsParam friends) {
        friendsService.addShard(friends);
        return RT.ok();
    }

    /**
     * 发布朋友圈
     *
     * @param friends
     * @return
     */
    @PostMapping("/publishFriends")
    @SaCheckLogin
    public RT publishFriends(@RequestBody DcUserFriendsParam friends) {
        friendsService.publishFriends(friends);
        return RT.ok();
    }

    /**
     * 获取评论列表
     *
     * @param friends
     * @return
     */
    @PostMapping("/getCommentList")
    public RT getCommentList(@RequestBody DcUserFriendsParam friends) {
        List<CommentListVo> commentList = friendsService.getCommentList(friends);
        return RT.ok(commentList);
    }

    /**
     * 添加收藏
     *
     * @param friends
     * @return
     */
    @PostMapping("/addFavorite")
    public RT addFavorite(@RequestBody DcUserFriendsParam friends) {
        friendsService.addFavorite(friends);
        return RT.ok();
    }

    /**
     * 添加收藏
     *
     * @param friends
     * @return
     */
    @PostMapping("/removeFavorite")
    public RT removeFavorite(@RequestBody DcUserFriendsParam friends) {
        friendsService.removeFavorite(friends);
        return RT.ok();
    }

    @PostMapping("/publishComment")
    public RT publishComment(@RequestBody DcUserFriendsComment friends) {
        friends.setUserId(LoginManager.getUserId());
        friendsCommentService.save(friends);
        return RT.ok();
    }
}
